package com.mhz.cae.objects;

import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;

import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;

public class Block {

	// The object coordonates
	private final float mX;
	private final float mY;
	private final float mWidth;
	private final float mHeight;
	private final float mAngle;

	private static final FixtureDef BLOCK_FIXURE_DEF = PhysicsFactory.createFixtureDef(0, 0f, 0.5f);

	// Sprite
	private Shape mFace;

	private Block(final float pX, final float pY, final float pWidth, final float pHeight, final float pAngle) {
		this.mX = pX;
		this.mY = pY;
		this.mWidth = pWidth;
		this.mHeight = pHeight;
		this.mAngle = pAngle;
	}

	public static Block createObject(final float pX, final float pY, final float pWidth, final float pHeight) {
		return new Block(pX, pY, pWidth, pHeight, 0);
	}

	public static Block createObject(final float pX, final float pY, final float pWidth, final float pHeight, final float pAngle) {
		return new Block(pX, pY, pWidth, pHeight, pAngle);
	}

	public void initObject(final PhysicsWorld physicsWorld, final Scene scene) {
		// Create Face
		mFace = new Rectangle(mX, mY, mWidth, mHeight);
		mFace.setRotation(mAngle);
		// Attach Face to the scene
		scene.attachChild(mFace);
		// Create Body
		PhysicsFactory.createBoxBody(physicsWorld, mFace, BodyType.StaticBody, BLOCK_FIXURE_DEF);
	}

}
